package com.blq.web.PayoutInformation.controller;

import java.util.List;
import java.util.Arrays;

import com.blq.web.PayoutInformation.domain.PayoutInformation;
import lombok.RequiredArgsConstructor;
import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.*;
import cn.dev33.satoken.annotation.SaCheckPermission;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import com.blq.common.annotation.RepeatSubmit;
import com.blq.common.annotation.Log;
import com.blq.common.core.controller.BaseController;
import com.blq.common.core.domain.PageQuery;
import com.blq.common.core.domain.R;
import com.blq.common.core.validate.AddGroup;
import com.blq.common.core.validate.EditGroup;
import com.blq.common.enums.BusinessType;
import com.blq.common.utils.poi.ExcelUtil;
import com.blq.web.PayoutInformation.domain.vo.PayoutInformationVo;
import com.blq.web.PayoutInformation.domain.bo.PayoutInformationBo;
import com.blq.web.PayoutInformation.service.IPayoutInformationService;
import com.blq.common.core.page.TableDataInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiParam;
import io.swagger.annotations.ApiOperation;

/**
 * 收款信息Controller
 *
 * @author Blq
 * @date 2022-09-13
 */
@Validated
@Api(value = "收款信息控制器", tags = {"收款信息管理"})
@RequiredArgsConstructor
@RestController
@RequestMapping("/web/PayoutInformation")
public class PayoutInformationController extends BaseController {

    private final IPayoutInformationService iPayoutInformationService;

    /**
     * 查询收款信息列表
     */
    @ApiOperation("查询收款信息列表")
    @SaCheckPermission("web:PayoutInformation:list")
    @GetMapping("/list")
    public TableDataInfo<PayoutInformation> list(PayoutInformationBo bo, PageQuery pageQuery) {
        return iPayoutInformationService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出收款信息列表
     */
    @ApiOperation("导出收款信息列表")
    @SaCheckPermission("web:PayoutInformation:export")
    @Log(title = "收款信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(PayoutInformationBo bo, HttpServletResponse response) {
        List<PayoutInformationVo> list = iPayoutInformationService.queryList(bo);
        ExcelUtil.exportExcel(list, "收款信息", PayoutInformationVo.class, response);
    }

    /**
     * 获取收款信息详细信息
     */
    @ApiOperation("获取收款信息详细信息")
    @SaCheckPermission("web:PayoutInformation:query")
    @GetMapping("/{payoutKey}")
    public R<PayoutInformationVo> getInfo(@ApiParam("主键")
                                          @NotNull(message = "主键不能为空")
                                          @PathVariable("payoutKey") String payoutKey) {
        return R.ok(iPayoutInformationService.queryById(payoutKey));
    }

    /**
     * 新增收款信息
     */
    @ApiOperation("新增收款信息")
    @SaCheckPermission("web:PayoutInformation:add")
    @Log(title = "收款信息", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody PayoutInformationBo bo) {
        return toAjax(iPayoutInformationService.insertByBo(bo) ? 1 : 0);
    }

    /**
     * 修改收款信息
     */
    @ApiOperation("修改收款信息")
    @SaCheckPermission("web:PayoutInformation:edit")
    @Log(title = "收款信息", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody PayoutInformationBo bo) {
        return toAjax(iPayoutInformationService.updateByBo(bo) ? 1 : 0);
    }

    /**
     * 删除收款信息
     */
    @ApiOperation("删除收款信息")
    @SaCheckPermission("web:PayoutInformation:remove")
    @Log(title = "收款信息", businessType = BusinessType.DELETE)
    @DeleteMapping("/{payoutKeys}")
    public R<Void> remove(@ApiParam("主键串")
                          @NotEmpty(message = "主键不能为空")
                          @PathVariable String[] payoutKeys) {
        return toAjax(iPayoutInformationService.deleteWithValidByIds(Arrays.asList(payoutKeys), true) ? 1 : 0);
    }
}
